package com.qianfeng.mapper.mapper;

import com.qianfeng.mapper.pojo.TbUser;
import com.qianfeng.mapper.provider.MyUserProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Zhaohao on 2022/5/17 22:03
 *
 * @version 1.0
 * @auther Zhaohao
 * @since 1.0
 */
public interface UserMapper {
    @Select("   SELECT * FROM tb_user WHERE id = #{id}")
    @ResultMap("usermap")
    TbUser findById(Long id);
    @Select("select * from tb_user")
    List<TbUser> findAll();
    @Insert("INSERT into tb_user(username,password,email,gender,flag,role,code,nick_name) values(#{username},#{password},#{email},#{gender},#{flag},#{role},#{code},#{nickName})")
    int addUser(TbUser user);
    @Update("<script>  update tb_user\n" +
            "    <set>\n" +
            "        <if test=\"username!=null and username!=''\">\n" +
            "            username=#{username}\n" +
            "        </if>\n" +
            "        <if test=\"password!=null and password!=''\">\n" +
            "            password=#{password}\n" +
            "        </if>\n" +
            "        <if test=\"email!=null and email!=''\">\n" +
            "             email=#{email}\n" +
            "        </if>\n" +
            "        where id=#{id}\n" +
            "    </set></script>")
    void updateUser(TbUser user);
    @UpdateProvider(type= MyUserProvider.class,method ="updateUser")
    void  updateUser2(TbUser user);
}
